home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / INTSTR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-03  |  1.0 KB  |  48 lines

  1. /*
  2.  * a header of the class INTSTR_ELEMENT
  3.  * Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  4.  */
  5.  
  6. #ifndef _INTSTR_H_
  7. #define _INTSTR_H_
  8.  
  9. #include <string.h>
  10.  
  11. #include "common/typedef.h"
  12.  
  13. class INTSTR_ELEMENT {
  14. public:
  15.   uint        no;
  16.   const char* str;
  17. };
  18.  
  19. class INTSTR_TABLE {
  20.   const INTSTR_ELEMENT* m_table;
  21.   uint                  m_last;
  22. public:
  23.   INTSTR_TABLE(const INTSTR_ELEMENT* table, uint last)
  24.     : m_table(table),
  25.       m_last (last ) {}
  26.   INTSTR_TABLE(void) {}
  27.   const char* get_str(uint no) const {
  28.     for(uint i = 0; m_table[i].no != m_last; i++) {
  29.       const INTSTR_ELEMENT& current = m_table[i];
  30.       if(current.no == no) {
  31.         return current.str;
  32.       }
  33.     }
  34.     return NULL;
  35.   }
  36.   uint get_no(const char* str) const {
  37.     for(uint i = 0; m_table[i].no != m_last; i++) {
  38.       const INTSTR_ELEMENT& current = m_table[i];
  39.       if(!strcmp(current.str, str)) {
  40.         return current.no;
  41.       }
  42.     }
  43.     return m_last;
  44.   }
  45. };
  46.  
  47. #endif /* _INTSTR_H_ */
  48.